<template>
  <div class="dialog">
    <el-dialog
      title="告警处理"
      :visible.sync="showDialog"
      width="35%"
      top="0"
      :close-on-click-modal="false"
      @close="cancel"
    >
      <el-form
        ref="ruleForm"
        label-position="left"
        :model="formData"
        :rules="rules"
        class="el-form"
      >
        <el-form-item label="处理结果：" class="w100p" prop="result">
          <el-select
            v-model="formData.result"
            clearable
            filterable
            placeholder="处理结果选择"
            @change="defaulthandmet"
          >
            <el-option
              v-for="item of defaulthandingArr"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item v-if="formData.result==='OTHER'" label="处理过程：" class="w100p" prop="processMode">
          <el-input
            v-model="formData.processMode"
            type="textarea"
            :autosize="{ minRows: 4, maxRows: 10}"
            clearable
            placeholder="请输入处理过程"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button class="cancelbtn" @click="cancel()">取 消</el-button>
        <el-button type="primary" class="savebtn" @click="save('ruleForm')">保 存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import historicalAlarmRecordApi from "@/api/monitoring-alarm/historical-alarm-record/index";

export default {
  name: '',
  components: { },
  props: {
    // 弹框名称
    show: {
      type: Boolean,
      default: false
    },
    editObject: {
      type: [Object],
      default: () => {
        return {}
      }
    }
  },
  data() {
    return {
      formData: { },
      rules: {
        result: [
          { required: true, message: "请输入处理结果", trigger: ["change", "blur"] }
        ]
      },
      showDialog: this.show,
      defaulthandingArr: [{ name: '已处理完成', id: 'COMPLETED' }, { name: '未处理', id: 'UNCOMPLETED' }, { name: '其他', id: 'OTHER' }]
    };
  },
  watch: {
    show(v) {
      this.showDialog = v;
    }
  },
  created() {
  },
  mounted() {
  },
  methods: {
    save(formData) {
      this.$refs[formData].validate(valid => {
        if (valid) {
          this.formData.disposeStatus = true
          this.formData.disposeTime = this.formatDateTime(new Date())
          alert(this.formData.disposeTime)
          this.formData.alarmMessageId = this.editObject.alarmMessageId
          historicalAlarmRecordApi.editlist(this.formData).then(res => {
            if (res.code === 1) {
              this.$message.success("处理成功！");
              this.close()
            } else {
              this.$message.error("处理失败！");
            }
          });
        } else {
          return false;
        }
      });
    },
    defaulthandmet(e){
      console.log(e);
    },
    formatDateTime(val) {
      var time = new Date(val);
      var year = time.getFullYear(); // 取得4位数的年份
      var month = time.getMonth() + 1; // 取得日期中的月份，其中0表示1月，11表示12月
      var date = time.getDate(); // 返回日期月份中的天数（1到31）
      var hour = time.getHours(); // 返回日期中的小时数（0到23）
      var minute = time.getMinutes(); // 返回日期中的分钟数（0到59）
      var second = time.getSeconds(); // 返回日期中的秒数（0到59）
      return year + "-" + month + "-" + date + " " + hour + ':'+ minute+':'+ second;
      // return year + "年" + month + "月" + date + " " + hour + ":" + minute + ":" + second;
    },
    close() {
      this.$emit("closeDialog");
    },
    cancel() {
      this.$emit("cancelDialog");
    }
  }
};
</script>

<style lang="scss" scoped>
</style>
